# coding=utf-8

import os
import xlrd
import xlwt

target_dirpath = r"I:\test0819-12"
target_filename = '1.xls'


def xls_R():
    # 1读xls的超链接和文字
    xls_file = xlrd.open_workbook(target_dirpath + "\\" + target_filename)
#     xls_sheets = xls_file.sheets()
    xls_sheet = xls_file.sheet_by_index(0)
    
    # 行数列数
    nrows, ncols = xls_sheet.nrows, xls_sheet.ncols 
    print("nrows=%s ncols=%s" % (nrows, ncols))
    # 单元
    for r in range(nrows):
        for c in range(ncols):
            value = xls_sheet.cell_value(r, c)
            type = xls_sheet.cell_type(r, c)
            print("(%s, %s)=%s\t%s" % (r, c, value, type))
    # 合并的单元格？
    merged_cells = xls_sheet.merged_cells
    print("merged_cells.len=%s merged_cells=%s" % (len(merged_cells), merged_cells))
    # 超链接


def xls_W():
    workbook = xlwt.Workbook(encoding='utf-8')
    booksheet = workbook.add_sheet('Sheet 1', cell_overwrite_ok=True)
    
    #  写单元格
    booksheet.write(0, 0, 34)
    # 合并单元格
    
    # 写&合并单元格


def xls_RW():
    return


if __name__ == '__main__':
    
    # 1读xls的超链接和文字
    xls_R()
    
    # 2写xls的超链接和文字
#     xls_W()
    
    # 3更新xls的超链接和文字
    
